package com.example.tellwin.mine.act;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.base.CpBaseActivty;
import com.example.tellwin.base.DaggerRxComponent;
import com.example.tellwin.mine.adapter.AttentionVpAdapter;
import com.example.tellwin.mine.bean.AttentionQuestionBean;
import com.example.tellwin.mine.bean.AttentionTeacherBean;
import com.example.tellwin.mine.contract.MineAttentionContract;
import com.example.tellwin.mine.fragment.AttentionQuestionFragment;
import com.example.tellwin.mine.fragment.AttentionTeacherFragment;
import com.example.tellwin.mine.presenter.MineAttentionPresenter;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MineAttentionActivity extends CpBaseActivty implements MineAttentionContract.View {

    @BindView(R.id.attention_vp)
    ViewPager attentionVp;
    @BindView(R.id.question_rbtn)
    RadioButton questionRbtn;
    @BindView(R.id.teacher_rbtn)
    RadioButton teacherRbtn;
    @BindView(R.id.mine_attention_tab)
    RadioGroup mineAttentionTab;

    private String[] titles = new String[]{"问题", "老师"};
    private AttentionVpAdapter attentionVpAdapter;

    @Inject
    MineAttentionPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_attention);
        ButterKnife.bind(this);
        initViews();
        initEvents();
        initDatas();
    }

    @Override
    protected void initViews() {

        DaggerRxComponent.builder()
                .baseAppComponent(MainApplication.getAppComponent())
                .build()
                .inject(this);
        mPresenter.attachView(this);

        List<Fragment> fragments = new ArrayList<>();
        fragments.add(new AttentionQuestionFragment());
        fragments.add(new AttentionTeacherFragment());
        attentionVpAdapter = new AttentionVpAdapter(getSupportFragmentManager(), fragments);
        attentionVp.setAdapter(attentionVpAdapter);
    }

    @Override
    protected void initEvents() {
        mineAttentionTab.check(R.id.question_rbtn);
        mineAttentionTab.setOnCheckedChangeListener((group, checkedId) -> {
            switch (checkedId){
                case R.id.question_rbtn:
                    attentionVp.setCurrentItem(0);
                    break;
                case R.id.teacher_rbtn:
                    attentionVp.setCurrentItem(1);
                    break;
            }
        });
        attentionVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
                        mineAttentionTab.check(R.id.question_rbtn);
                        break;
                    case 1:
                        mineAttentionTab.check(R.id.teacher_rbtn);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initDatas() {
        setTitle(R.string.mine_attention);
    }

    @Override
    public void attentionQuestionListResult(boolean isLoadMore, List<AttentionQuestionBean> attentionQuestionBeans) {

    }

    @Override
    public void attentionTeacherListResult(boolean isLoadMore, List<AttentionTeacherBean> attentionQuestionBeans) {

    }
}
